"""
房地产
"""
import time

from com.data.extract import Extract, DefaultStrategy, HttpRequest, HttpMethodEnum


# 房地产开发投资情况
class DevelopmentInvestmentExtract(Extract.Extract):
    def __init__(self, strategy=DefaultStrategy.DefaultStrategy):
        query_time = str(round(time.time() * 1000 - 10 * 1000))
        request = HttpRequest.HttpRequest(
            "http://data.stats.gov.cn/easyquery.htm?m=QueryData&dbcode=hgyd&rowcode=zb&colcode=sj&wds=%5B%5D&dfwds"
            "=%5B%7B%22wdcode%22%3A%22zb%22%2C%22valuecode%22%3A%22A0601%22%7D%5D&k1=" + query_time +
            "&h=1",
            HttpMethodEnum.HttpMethodEnum.GET)
        super().__init__(request, strategy)


# 房地产开发投资实际到位资金
class FundsExtractExtract(Extract.Extract):
    def __init__(self, strategy=DefaultStrategy.DefaultStrategy):
        request = HttpRequest.HttpRequest(
            "http://data.stats.gov.cn/easyquery.htm?m=QueryData&dbcode=hgyd&rowcode=zb&colcode=sj&wds=%5B%5D&dfwds"
            "=%5B%7B%22wdcode%22%3A%22zb%22%2C%22valuecode%22%3A%22A0602%22%7D%5D&k1="+str(
                round(time.time() * 1000))+"&h=1",
            HttpMethodEnum.HttpMethodEnum.GET)
        super().__init__(request, strategy)


# 房地产土地开发与销售情况
class LandDevelopmentAndSalesExtract(Extract.Extract):
    def __init__(self, strategy=DefaultStrategy.DefaultStrategy):
        request = HttpRequest.HttpRequest(
            "http://data.stats.gov.cn/easyquery.htm?m=QueryData&dbcode=hgyd&rowcode=zb&colcode=sj&wds=%5B%5D&dfwds"
            "=%5B%7B%22wdcode%22%3A%22zb%22%2C%22valuecode%22%3A%22A0603%22%7D%5D&k1="+str(
                round(time.time() * 1000))+"&h=1",
            HttpMethodEnum.HttpMethodEnum.GET)
        super().__init__(request, strategy)


# 房地产施工、竣工面积
class ConstructionCompletionAreaExtract(Extract.Extract):
    def __init__(self, strategy=DefaultStrategy.DefaultStrategy):
        request = HttpRequest.HttpRequest(
            "http://data.stats.gov.cn/easyquery.htm?m=QueryData&dbcode=hgyd&rowcode=zb&colcode=sj&wds=%5B%5D&dfwds"
            "=%5B%7B%22wdcode%22%3A%22zb%22%2C%22valuecode%22%3A%22A0604%22%7D%5D&k1="+str(
                round(time.time() * 1000))+"&h=1",
            HttpMethodEnum.HttpMethodEnum.GET)
        super().__init__(request, strategy)


# 商品住宅施工、竣工面积
class CompletedAreaOfResidentialConstructionExtract(Extract.Extract):
    def __init__(self, strategy=DefaultStrategy.DefaultStrategy):
        request = HttpRequest.HttpRequest(
            "http://data.stats.gov.cn/easyquery.htm?m=QueryData&dbcode=hgyd&rowcode=zb&colcode=sj&wds=%5B%5D&dfwds"
            "=%5B%7B%22wdcode%22%3A%22zb%22%2C%22valuecode%22%3A%22A0605%22%7D%5D&k1="+str(
                round(time.time() * 1000))+"&h=1",
            HttpMethodEnum.HttpMethodEnum.GET)
        super().__init__(request, strategy)


# 办公楼施工、竣工面积
class ConstructionCompletedAreaOfOfficeBuildingExtract(Extract.Extract):
    def __init__(self, strategy=DefaultStrategy.DefaultStrategy):
        request = HttpRequest.HttpRequest(
            "http://data.stats.gov.cn/easyquery.htm?m=QueryData&dbcode=hgyd&rowcode=zb&colcode=sj&wds=%5B%5D&dfwds"
            "=%5B%7B%22wdcode%22%3A%22zb%22%2C%22valuecode%22%3A%22A0606%22%7D%5D&k1="+str(
                round(time.time() * 1000))+"&h=1",
            HttpMethodEnum.HttpMethodEnum.GET)
        super().__init__(request, strategy)


# 商业营业用房施工、竣工面积
class ConstructionCompletedAreaOfBusinessHouseExtract(Extract.Extract):
    def __init__(self, strategy=DefaultStrategy.DefaultStrategy):
        request = HttpRequest.HttpRequest(
            "http://data.stats.gov.cn/easyquery.htm?m=QueryData&dbcode=hgyd&rowcode=zb&colcode=sj&wds=%5B%5D&dfwds"
            "=%5B%7B%22wdcode%22%3A%22zb%22%2C%22valuecode%22%3A%22A0607%22%7D%5D&k1="+str(
                round(time.time() * 1000))+"&h=1",
            HttpMethodEnum.HttpMethodEnum.GET)
        super().__init__(request, strategy)


# 商品房销售面积
class SalesAreaOfCommercialHousingExtract(Extract.Extract):
    def __init__(self, strategy=DefaultStrategy.DefaultStrategy):
        request = HttpRequest.HttpRequest(
            "http://data.stats.gov.cn/easyquery.htm?m=QueryData&dbcode=hgyd&rowcode=zb&colcode=sj&wds=%5B%5D&dfwds"
            "=%5B%7B%22wdcode%22%3A%22zb%22%2C%22valuecode%22%3A%22A0608%22%7D%5D&k1="+str(
                round(time.time() * 1000))+"&h=1",
            HttpMethodEnum.HttpMethodEnum.GET)
        super().__init__(request, strategy)


# 商品房销售额
class SalesOfCommercialHousingExtract(Extract.Extract):
    def __init__(self, strategy=DefaultStrategy.DefaultStrategy):
        request = HttpRequest.HttpRequest(
            "http://data.stats.gov.cn/easyquery.htm?m=QueryData&dbcode=hgyd&rowcode=zb&colcode=sj&wds=%5B%5D&dfwds"
            "=%5B%7B%22wdcode%22%3A%22zb%22%2C%22valuecode%22%3A%22A0609%22%7D%5D&k1="+str(
                round(time.time() * 1000))+"&h=1",
            HttpMethodEnum.HttpMethodEnum.GET)
        super().__init__(request, strategy)


# 商品住宅销售面积
class AreaOfCommercialHousingExtract(Extract.Extract):
    def __init__(self, strategy=DefaultStrategy.DefaultStrategy):
        request = HttpRequest.HttpRequest(
            "http://data.stats.gov.cn/easyquery.htm?m=QueryData&dbcode=hgyd&rowcode=zb&colcode=sj&wds=%5B%5D&dfwds"
            "=%5B%7B%22wdcode%22%3A%22zb%22%2C%22valuecode%22%3A%22A060A%22%7D%5D&k1="+str(
                round(time.time() * 1000))+"&h=1",
            HttpMethodEnum.HttpMethodEnum.GET)
        super().__init__(request, strategy)


# 商品住宅销售额
class CommercialHousingExtract(Extract.Extract):
    def __init__(self, strategy=DefaultStrategy.DefaultStrategy):
        request = HttpRequest.HttpRequest(
            "http://data.stats.gov.cn/easyquery.htm?m=QueryData&dbcode=hgyd&rowcode=zb&colcode=sj&wds=%5B%5D&dfwds"
            "=%5B%7B%22wdcode%22%3A%22zb%22%2C%22valuecode%22%3A%22A060B%22%7D%5D&k1="+str(
                round(time.time() * 1000))+"&h=1",
            HttpMethodEnum.HttpMethodEnum.GET)
        super().__init__(request, strategy)


# 办公楼销售面积
class SalesAreaOfOfficeBuildingExtract(Extract.Extract):
    def __init__(self, strategy=DefaultStrategy.DefaultStrategy):
        request = HttpRequest.HttpRequest(
            "http://data.stats.gov.cn/easyquery.htm?m=QueryData&dbcode=hgyd&rowcode=zb&colcode=sj&wds=%5B%5D&dfwds"
            "=%5B%7B%22wdcode%22%3A%22zb%22%2C%22valuecode%22%3A%22A060C%22%7D%5D&k1="+str(
                round(time.time() * 1000))+"&h=1",
            HttpMethodEnum.HttpMethodEnum.GET)
        super().__init__(request, strategy)


# 办公楼销售额
class CommercialOfficeBuildingExtract(Extract.Extract):
    def __init__(self, strategy=DefaultStrategy.DefaultStrategy):
        request = HttpRequest.HttpRequest(
            "http://data.stats.gov.cn/easyquery.htm?m=QueryData&dbcode=hgyd&rowcode=zb&colcode=sj&wds=%5B%5D&dfwds"
            "=%5B%7B%22wdcode%22%3A%22zb%22%2C%22valuecode%22%3A%22A060D%22%7D%5D&k1="+str(
                round(time.time() * 1000))+"&h=1",
            HttpMethodEnum.HttpMethodEnum.GET)
        super().__init__(request, strategy)


# 商业营业用房销售面积
class BusinessOfSalesAreaExtract(Extract.Extract):
    def __init__(self, strategy=DefaultStrategy.DefaultStrategy):
        request = HttpRequest.HttpRequest(
            "http://data.stats.gov.cn/easyquery.htm?m=QueryData&dbcode=hgyd&rowcode=zb&colcode=sj&wds=%5B%5D&dfwds"
            "=%5B%7B%22wdcode%22%3A%22zb%22%2C%22valuecode%22%3A%22A060E%22%7D%5D&k1="+str(
                round(time.time() * 1000))+"&h=1",
            HttpMethodEnum.HttpMethodEnum.GET)
        super().__init__(request, strategy)


# 商业营业用房销售额
class BusinessOfCommercialExtract(Extract.Extract):
    def __init__(self, strategy=DefaultStrategy.DefaultStrategy):
        request = HttpRequest.HttpRequest(
            "http://data.stats.gov.cn/easyquery.htm?m=QueryData&dbcode=hgyd&rowcode=zb&colcode=sj&wds=%5B%5D&dfwds"
            "=%5B%7B%22wdcode%22%3A%22zb%22%2C%22valuecode%22%3A%22A060F%22%7D%5D&k1="+str(
                round(time.time() * 1000))+"&h=1",
            HttpMethodEnum.HttpMethodEnum.GET)
        super().__init__(request, strategy)


if __name__ == "__main__":
    hourseExtract = DevelopmentInvestmentExtract()
    r = hourseExtract.extract()
    print(r.json())

    f = FundsExtractExtract()
    r_f = f.extract()
    print(r_f.json())

    lds = LandDevelopmentAndSalesExtract()
    r_lds = lds.extract()
    print(r_lds.json())

    cca = ConstructionCompletionAreaExtract()
    r_cca = cca.extract()
    print(r_cca.json())

    carc = CompletedAreaOfResidentialConstructionExtract()
    r_carc = carc.extract()
    print(r_carc.json())
